package com.wcar.user.controller;

import com.wcar.common.entity.User;
import com.wcar.common.entity.UserAddress;
import com.wcar.common.vo.Result;
import com.wcar.user.service.UserAddressService;
import org.apache.tomcat.jni.Address;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @program: four-wcar-idea
 * @description:
 * @author: 吴朝阳
 * @create: 2024-05-31 17:28
 **/
@RestController
@RequestMapping("/user")
public class UserAddressController {
    @Autowired
    private UserAddressService userService;
    //查询
    @GetMapping("/selectAddressById/{userId}")
    public Result<List<UserAddress>> selectAddress(@PathVariable Integer userId){
        System.out.println(userId+"!!!!!!!!!!!!!!");
        return userService.selectAddress(userId);
    }
    //编辑地址
    @PostMapping("/updateUserAddress")
    public Result<UserAddress> selectOneAddress(@RequestBody UserAddress userAddress){
        return userService.selectOneAddress(userAddress);
    }
    //查询编辑地址
    @GetMapping("/selectOneAddress/{id}")
    public Result<UserAddress> selectOne(@PathVariable Integer id){
        return userService.selectOne(id);
    }
    //城市 省份 区
    @GetMapping("/selectAreaCode")
    public Result<List<UserAddress>> selectCity(String country, String city, String province){
        return userService.selectCity(country,city,province);
    }
    //新增地址
    @PostMapping("/addAddress")
    public Result<UserAddress> insertUserAddress(@RequestBody UserAddress userAddress){
        return userService.insertUserAddress(userAddress);
    }
    //删除地址
    @DeleteMapping("/deleteUserAddress")
    public Result<UserAddress> deleteUserAddress(UserAddress addressId){
        return userService.deleteUserAddress(addressId);
    }
}
